package com.woniu.airent.controller;

import com.woniu.airent.dto.ReportDto;
import com.woniu.airent.service.ReportImgService;
import com.woniu.airent.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/report")
@Controller
public class ReportController {

    @Autowired
    ReportService reportService;

    @Autowired
    ReportImgService reportImgService;

    @RequestMapping("/addReport")
    @ResponseBody
    public String addReport(@RequestParam(value = "userName") String userName,
                            @RequestParam(value = "houseNumber") String houseNumber,
                            @RequestParam(value = "reportContent") String reportContent,
                            @RequestParam(value = "imgPath[]") String imgPath[]){
        String prefix = "https://airent-1303816068.cos.ap-shanghai.myqcloud.com/";
        for (int i = 0; i < imgPath.length; i++) {
            String path = prefix + imgPath[i];
            Integer addReportImg = reportImgService.addReportImg(houseNumber,path);
        }
        Integer addReport = reportService.addReport(userName,houseNumber,reportContent);
        return "1";
    }
}
